feat: Allow to extend and customize TUI with additional commands#2346
Open
shaj13 wants to merge 1 commit intodocker:mainfrom
Open
feat: Allow to extend and customize TUI with additional commands#2346shaj13 wants to merge 1 commit intodocker:mainfrom
shaj13 wants to merge 1 commit intodocker:mainfrom
Conversation
1144cac to
c444ac6
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Customizing the TUI currently requires forking the repository or building a UI from scratch. This limits docker-agent's potential to serve as an end-to-end framework where consumers can reuse the TUI while adding their own commands.
What was done
Immediateflag tocommands.Itemto control whether a command interrupts an ongoing streamParseSlashCommandto aParserstruct withNewParserconstructor, allowing consumers to build parsers with custom command categoriesWithCommandBuilderoption to allow consumers to provide custom command categories to the TUIDependency Resolution
At first, I started with an interface that
appModelimplements which returns internal objects like*app.App,*service.SessionState,chat.Page, andeditor.Editor. However, that interface can't be set in the main package as it may not serve future changes, unless it's set in a dedicated package with a guarantee there will be no circular imports.So I added a dynamic dependency resolution pattern via
core.Resolve[T]- a type-safe generic function that retrieves dependencies from anytea.ModelimplementingResolve(any) any.It’s better and more idiomatic to avoid this approach. Instead, define a well-declared interface that appModel implements to return the underlying objects, and place that interface in its own standalone package.
Usage:
This may not be the final implementation as I am looking for feedback. I'm not sure if you're willing to allow TUI customization, but I think it would be very useful.